//
//  MeSetUpView.m
//  QT
//
//  Created by 甘世清 on 2024/12/30.
//

#import "MeSetUpView.h"
#import "MeSetUpTableViewCell.h"
#import "LoginViewController.h"
#import "IntroViewController.h"
#import "OutViewController.h"
#import "BlackListViewController.h"
#import "AgreementViewController.h"
#import "FeedbackViewController.h"
#import "HistoryViewController.h"
@implementation MeSetUpView

- (void)SQ_UIViewForSelfView{
    
    self.backgroundColor = UIColor.whiteColor;
    [self addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self).insets(UIEdgeInsetsMake(TopHeight, 0, 100+FootHeight,0));
    }];
    
    SQCustomButton * minView = [[SQCustomButton alloc]initType:SQCustomButtonLeftImageType imageSize:CGSizeMake(18, 18) midmargin:10];
    minView.layer.cornerRadius = 8;
    minView.backgroundColor = UIColor.whiteColor;
    minView.layer.borderColor = SQHexColor(@"#000000", 0.7).CGColor;
    minView.layer.borderWidth = 1;
    minView.image = SQGetImage(@"退出");
    minView.text = SQNSLocalString(@"退出");
    minView.textColor = SQColor333333;
    minView.font = FONT_MEDIUM(14);
    [self addSubview:minView];
    [minView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.top.equalTo(self.tableView.mas_bottom).offset(10);
            make.width.mas_equalTo(150);
            make.height.mas_equalTo(40);
    }];
  
    [minView setTouchBlock:^(SQCustomButton * _Nonnull button) {
        [UserModel clearLocalUserModel];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[LoginViewController alloc]init]];
         [Manager SQ_getCurrentViewController].view.window.rootViewController = nav;
    }];
    
    [self SQ_Header];
}
-(void)SQ_Header{
    self.jsonArray = [[NSMutableArray alloc]initWithObjects:@"浏览历史",@"反馈问题",@"黑名单",@"关于",@"协议",@"注销", nil];
    [self.tableView reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
   return self.jsonArray.count ;
}

 
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MeSetUpTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MeSetUpTableViewCell"];
    if (!cell) {
        cell = [[MeSetUpTableViewCell alloc] initWithStyle:(UITableViewCellStyleValue1) reuseIdentifier:@"MeSetUpTableViewCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
     [cell SQ_setname:[self.jsonArray  objectAtIndex:indexPath.item]];
    return cell;
}
 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString * name = [self.jsonArray  objectAtIndex:indexPath.item];
    if ([name isEqualToString:@"关于"]) {
        IntroViewController * vc = [[IntroViewController alloc]init];
        [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
    } else  if ([name isEqualToString:@"注销"]) {
        OutViewController* vc = [[OutViewController alloc]init];
        [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
    }else  if ([name isEqualToString:@"黑名单"]) {
        BlackListViewController* vc = [[BlackListViewController alloc]init];
        [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
    }else  if ([name isEqualToString:@"协议"]) {
        AgreementViewController* vc = [[AgreementViewController alloc]init];
        [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
    }else  if ([name isEqualToString:@"反馈问题"]) {
        FeedbackViewController* vc = [[FeedbackViewController alloc]init];
        [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
    }else  if ([name isEqualToString:@"浏览历史"]) {
        HistoryViewController * vc = [[HistoryViewController alloc]init];
        [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
    }
    
}
 
-(NSMutableArray*)jsonArray
{
    if (!_jsonArray) {
        _jsonArray = [[NSMutableArray alloc]init];
    }
    return _jsonArray;
}

-(UITableView*)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDETH, 0) style:UITableViewStylePlain];
        _tableView.dataSource = self;
        _tableView.delegate = self;
       
        if (@available(iOS 15.0, *)) {
            _tableView.sectionHeaderTopPadding = 0.01; // 这个属性，设置为0 时，headerView会随着滑动，给个最小值，就不会滑动了。
         }
        _tableView.allowsMultipleSelection = NO;
        if (@available(iOS 13.0, *)) {
            _tableView.automaticallyAdjustsScrollIndicatorInsets = NO;
        } else {
            // Fallback on earlier versions
        }
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.tableFooterView = [UIView new];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        if (@available(iOS 11.0, *)) {
            _tableView.estimatedSectionHeaderHeight = 0;
            _tableView.estimatedSectionFooterHeight = 0;
            _tableView.estimatedRowHeight = 0;
        }
    }
    return _tableView;
}

 

@end
